package com.artisan.web.action;

import com.artisan.common.pojo.PageBean;
import com.artisan.common.pojo.PageParam;
import com.artisan.medium.admin.service.UserService;
import com.artisan.model.Customer;
import com.artisan.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by yang on 2017/7/3.
 */
@Controller
@RequestMapping("/admin/user/")
public class UserController {
    @Autowired
    public UserService userService;

    @RequestMapping("user_list")
    public ModelAndView user_list(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Integer> result = new HashMap<>();
        return new ModelAndView("user/user_list", result);
    }

    @ResponseBody
    @RequestMapping(value = "user_select", method = RequestMethod.GET)
    public PageBean user_select(HttpServletRequest request, Integer limit, Integer pageNumber, int offset, User user, String searchKey) throws Exception {
        Map<String, Object> paramMap = new HashMap<String, Object>(); // 业务条件查询参数
        paramMap.put("searchKey", searchKey);
        paramMap.put("user", user);
       return userService.listPage(new PageParam(offset / limit + 1, limit), paramMap);
    }
}
